<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Websocket广播通信测试</title>
    <script src="http://cdn.bootcss.com/stomp.js/2.3.3/stomp.min.js"></script>
    <script src="https://cdn.bootcss.com/sockjs-client/1.1.4/sockjs.min.js"></script>
    <script>
        var socket = new SockJS("http://localhost:15500/fetl/webSocketServer");
        var stompClient = Stomp.over(socket);
        window.onload = function () {
            connect();
        }
        //订阅消息
        function subscribe() {

            //stompClient.subscribe('/queue/message', function(response){
			stompClient.subscribe('/topic/log/sss', function(response){
                console(response);
                alert("/topic/getResponse 你接收到的消息为:" + response);
            });

        }
        function send() {
            stompClient.send("/app/broadcast", {},
                JSON.stringify({ 'name': 'testtest' }));
        }
        function connect() {

            stompClient.connect({
                    //这里可以改成token
                    Authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjIxOTg1NjQxNjAsImlhdCI6MTUzMTg5NzUwMCwidXNlcm5hbWUiOiJ6cXcxMSJ9.VFR2EKUx5BTYLDkDogiLA9LfNVoPjOzQ3rTWoEy7He4' // 携带客户端信息
                },
                function connectCallback(frame) {
                    // 连接成功时（服务器响应 CONNECTED 帧）的回调方法
                    alert("success");
                    subscribe();
                },
                function errorCallBack(error) {
                    // 连接失败时（服务器响应 ERROR 帧）的回调方法
                    alert("error");
                });
        }
        function disconnect() {
            if (stompClient != null) {
                stompClient.disconnect();
            }
//            setConnected(false);
            console.log("Disconnected");
        }
    </script>
</head>
<body>
<input type="text" id="info"/><button onclick="send();">发送</button>
</body>
</html>
